export default {
	namespaced: true,
	state: () => ({
		address: JSON.parse(uni.getStorageSync('address') || '{}'), //	家庭住址
		token: uni.getStorageSync('token') || '', //	用户token
		userinfo: JSON.parse(uni.getStorageSync('userinfo') || '{}'), //	个人信息
		redirectInfo: null
	}),
	mutations: {
		updateAddress(state, address) { //	更新地址
			state.address = address
			this.commit('m_user/saveAddressToStorage')
		},
		updateUserInfo(state, userinfo) { //	更新用户信息
			state.userinfo = userinfo
			this.commit('m_user/saveUserInfoToStorage')
		},
		updateToken(state, token) { //	更新用户token
			state.token = token
			this.commit('m_user/saveTokenToStorage')
		},
		updateRedirectInfo(state, info) { //	更新重定向
			state.redirectInfo = info
		},
		saveAddressToStorage(state) { //	把地址信息存储在本地
			uni.setStorageSync('address', JSON.stringify(state.address))
		},
		saveUserInfoToStorage(state) { //	把用户信息存储在本地
			uni.setStorageSync('userinfo', JSON.stringify(state.userinfo))
		},
		saveTokenToStorage(state) { //	把用户token存储在本地
			uni.setStorageSync('token', state.token)
		}
	},
	getters: {
		addstr(state) { //	添加详细地址
			if (!state.address.provinceName) {
				return ''
			}
			return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
		}
	}
}
